/*
 * FairyResource.h
 *
 *  Created on: 2013. 9. 12.
 *      Author: mega@gamevil.com
 */

#ifndef FAIRYGACHYARESOURCE_H_
#define FAIRYGACHYARESOURCE_H_

#include <map>
#include "../NLogic/Item.h"

namespace ProjectZ { namespace NResource {

class FairyGachyaData
{
public:
	struct Key
	{
		Key() : type(0), sub_type(0) {}
		Key(int rType, int rSubType) : type(rType), sub_type(rSubType) {}

		int type;
		int sub_type;

		bool operator == (const Key & rSide) const
		{
			if (this->type == rSide.type && this->sub_type == rSide.sub_type)
				return true;

			return false;
		}

		bool operator < (const Key & rSide) const
		{
			if (this->type < rSide.type)
			{
				return true;
			}
			else if (this->type == rSide.type)
			{
				if (this->sub_type < rSide.sub_type)
					return true;
			}

			return false;
		}
	};

public:
	struct Flyweight
	{
		int _TYPE;
		int _SUB_TYPE;
		int _VALUE1;
		int _VALUE2;
		int _VALUE3;
	};

public:
	typedef std::map<Key, Flyweight *> FAIRYTREE;

public:
	FairyGachyaData() {}
	virtual ~FairyGachyaData();

	bool LoadResource(int company, int saleCode);
	Flyweight * GetFly(Key & clsKey);

	FAIRYTREE & GetTree() { return clsFlyTree; }

private:
	void	Clear();
	void	PrintFlyTree(int company, int salecode);

private:
	FAIRYTREE clsFlyTree;
};

class FairyGachyaResource
{
public:
	enum FairyGachyaType
	{
		EM_FAIRY_GACHYA_LEVEL_RATE		= 1,		// 레벨 결정 확률
		EM_FAIRY_GACHYA_QUALITY_RATE,				// 등급 결정 확률
		EM_FAIRY_GACHYA_ATTR_RATE,					// 속성 결정 확률
		EM_FAIRY_GACHYA_BATTLETYPE_RATE,			// 전투 타입 결정 확률
		EM_FAIRY_GACHYA_BATTLETYPE_CONST,			// 전투 타입별 공격 및 방어 상수값
		EM_FAIRY_GACHYA_PASSIVE_RATE,				// 보유 패시브 결정 확률
		EM_FAIRY_GACHYA_BUFF_RATE,					// 보유 버프 결정 확률
		EM_FAIRY_GACHYA_TYPE_RATE,					// 페어리 결정 확률

		EM_FAIRY_GACHYA_LEVEL_RATE_EVENT		= 9,	// 이벤트 레벨 결정 확률
		EM_FAIRY_GACHYA_QUALITY_RATE_EVENT,				// 이벤트 등급 결정 확률
		EM_FAIRY_GACHYA_ATTR_RATE_EVENT,				// 이벤트 속성 결정 확률
		EM_FAIRY_GACHYA_BATTLETYPE_RATE_EVENT,			// 이벤트 전투 타입 결정 확률
		EM_FAIRY_GACHYA_BATTLETYPE_CONST_EVENT,			// 이벤트 전투 타입별 공격 및 방어 상수값
		EM_FAIRY_GACHYA_PASSIVE_RATE_EVENT,				// 이벤트 보유 패시브 결정 확률
		EM_FAIRY_GACHYA_BUFF_RATE_EVENT,				// 이벤트 보유 버프 결정 확률
		EM_FAIRY_GACHYA_TYPE_RATE_EVENT,				// 이벤트 페어리 결정 확률
	};
public:
	FairyGachyaResource();
	virtual ~FairyGachyaResource();

	bool LoadResource();

	FairyGachyaData::Flyweight * GetFly(int company, int saleCode, FairyGachyaData::Key & clsKey);

	void	SetBaseFairyInfo(User * pUser, NLogic::Item::Data & clsData, int classType);
	bool	FairyGachya(User * pUser, NLogic::Item::Data & clsData, int excludeType, int gachyaQuality);
	bool	FairyRebirth(User * pUser, NLogic::Item::Data & clsData, std::vector<NLogic::Item *> & fairyVector);
	int		FairyUltimateEvolution(User * pUser, NLogic::Item * pItem);
	int		FairyEvolution(User * pUser, NLogic::Item * pItem);

	void	FairyGachyaForTEST(User * pUser, int level);

private:
	bool	IsFairyGachyaEvent(User * pUser);
	int		GetFairyLevel(FairyGachyaData * pFairy, bool bEvent);
	int		GetFairyQuality(FairyGachyaData * pFairy, bool bEvent, int gachyaQuality);
	int		GetFairyAttrType(FairyGachyaData * pFairy, bool bEvent, int excludeType);
	int		GetFairyBattleType(FairyGachyaData * pFairy, bool bEvent);
	int		GetFairyPassiveCount(FairyGachyaData * pFairy, bool bEvent, int quality);
	int		GetFairyBuff(FairyGachyaData * pFairy, NResource::BalanceData * pBalance, bool bEvent, int quality);
	int		GetFairyType(FairyGachyaData * pFairy, bool bEvent);
	bool	SetFairyInfo(FairyGachyaData * pFairy, NResource::BalanceData * pBalance, NLogic::Item::Data & clsData, int passive, int buff, int fairyType, bool bEvent);

	FairyGachyaData * GetDataPtr(int company, int saleCode);

private:
	FairyGachyaData * pFairyAD;
	FairyGachyaData * pFairyIOS;
};

} /* NResource */ } /* ProjectZ */

#endif /* FAIRYGACHYARESOURCE_H_ */
